package com.wistech.search.solr.qp;

import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QParser;
import org.apache.solr.search.QParserPlugin;

/**
 * 扩展的 lucene QParser 使用它支持自定义的 query parser.
 * 
 * @author Steven Liu
 */
public class ChineseQParserPlugin extends QParserPlugin {

	public static String NAME = "chinese";
	private String opParam;

	@Override
	public QParser createParser(String qstr, SolrParams localParams,
			SolrParams params, SolrQueryRequest req) {
		return new ChineseQParser(qstr, params, params, req, opParam);
	}

	/**
	 * invoke args=null at {@link SolrCore#initQParsers()}
	 */
	@SuppressWarnings("rawtypes")
	public void init(NamedList args) {
		Object param = args.get("op");
		if (param != null) {
			opParam = param.toString();
		}
	}
}
